<?php
namespace app\item;

class Config implements \ArrayAccess
{
	private $data = [];

	public function __construct(Array $data = [])
	{
		$this->data = array_merge($this->data, $data);
	}

	public function offsetExists($key)
	{
		return isset($this->data[$key]);
	}

	public function offsetSet($key, $value)
	{
		$this->data[$key] = $value;
	}

	public function offsetGet($key)
	{
		return $this->data[$key];
	}

	public function offsetUnset($key)
	{
		unset($this->data[$key]);
	}

	// 数组切片
	public function slice($start, $end)
	{
		return array_slice($this->data, 0, count($this->data)-($start+$end));
	}

	public function __get($key)
	{
		return $this->data[$key] ?? null;
	}

	public function __set($key, $value)
	{
		$this->data[$key] = $value;
	}

	public function __invoke(Array $data = [])
	{
		$this->data = array_merge($this->data, $data);
		return $this;
	}
}
